package com.formula.datastructure.question.tree;

// traverse
public class Quest02 {

}

class Tree02 {
    private Node02 root;

    public void preOrder() {
        if (root != null) {
            root.preOrder();
        }
    }
}

class Node02 {
    private Integer data;
    private Node02 leftChild;
    private Node02 rightChild;

    public void preOrder() {
        visit();
        if (leftChild != null) {
            leftChild.preOrder();
        }
        if (rightChild != null) {
            rightChild.preOrder();
        }
    }

    public void inOrder() {
        if (leftChild != null) {
            leftChild.inOrder();
        }
        visit();
        if (rightChild != null) {
            rightChild.inOrder();
        }
    }

    public void postOrder() {
        if (leftChild != null) {
            leftChild.postOrder();
        }
        if (rightChild != null) {
            rightChild.postOrder();
        }
        visit();
    }

    void visit() {
        System.out.println(data);
    }
}
